<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var arr = [1, 2, 45, 44, 45, 2, 89, 1, 1, 2, 1, 2];
        // ***\*第一种：new Set()\****
        var box = Array.from(new Set(arr));
        var box = [...new Set(arr)];
        console.log(box);
        // ***\*第二种：indexOf()\****
        var box = [];
        for (var i = 0; i < arr.length; i++) {
            if (box.indexOf(arr[i]) == -1) {
                box.push(arr[i])
            }
        }
        console.log(box);
        // ***\*第三种：splice()\****
        for (var i = 0; i < arr.length; i++) {
            for (var j = i + 1; j < arr.length; j++) {
                if (arr[i] == arr[j]) {
                    arr.splice(j, 1);
                }
            }
        }
        console.log(arr);
        for (var i = 0; i < arr.length; i++) { for (var j = i + 1; j < arr.length; j++) { if (arr[i] == arr[j]) { arr.splice(j, 1); } } } console.log(arr); var box = Array.from(new Set(arr)); var box = [...new Set(arr)]; console.log(box);
    </script>
</body>

</html>